import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ConfigService } from '@nestjs/config';
import { BaseService } from '@wwjCommon/base/base.service';
import { CacheService } from '@wwjCommon/cache/cache.service';
import { LoggingService } from '@wwjCommon/logging/logging.service';
import { UploadService } from '@wwjVendor/upload/upload.service';
import { PayService } from '@wwjVendor/pay/pay.service';
import { SmsService } from '@wwjVendor/sms/sms.service';
import { NoticeService } from '@wwjVendor/notice/notice.service';

@Injectable()
export class CoreSysConfigService extends BaseService<any> {
  private readonly logger = new Logger(CoreSysConfigService.name);

  constructor(
    @InjectRepository(Object)
    protected readonly repository: Repository<any>,
    private readonly cacheService: CacheService,
    private readonly configService: ConfigService,
    private readonly loggingService: LoggingService,
    private readonly uploadService: UploadService,
    private readonly payService: PayService,
    private readonly smsService: SmsService,
    private readonly noticeService: NoticeService,
  ) {
    super(repository);
  }

  /**
   * getSceneDomain
   * 对应 PHP: CoreSysConfigService_core::getSceneDomain()
   * 逻辑类型: undefined - undefined
   */
  async getSceneDomain(site_id: number) {
    // 基于PHP真实逻辑: getSceneDomain
    // PHP原文: $wap_domain = !empty(env("system.wap_domain")) ? preg_replace('#/$#', '', env("system.wap_domain")) : request()->domain();         $web_domain = !empt...
const wap_domain = !!env("system.wap_domain")) ? preg_replace('#/$#', '', env("system.wap_domain")) : request().domain(];
        const web_domain = !!env("system.web_domain")) ? preg_replace('#/$#', '', env("system.web_domain")) : request().domain(];
        const site_domain = ( this.coreSiteService ).getSiteCache(site_id)[ 'site_domain' ] || '';
        const service_domain = request().domain(];

        return [
            wap_domain: site_domain ? ( request().isSsl() ? "https://" : "http://" ) . site_domain : wap_domain,
            wap_url: site_domain ? ( request().isSsl() ? "https://" : "http://" ) . site_domain  + '/wap" : wap_domain  + '/wap/" . site_id,
            web_url: site_domain ? ( request().isSsl() ? "https://" : "http://" ) . site_domain  + '/web" : web_domain  + '/web/" . site_id,
            service_domain: service_domain
        ];
    }

    /**
     * 获取版权信息(网站整体，不按照站点设置)
     * @return array|mixed
     */
    async getCopyright(site_id)
    {
        const info = ( this.coreConfigService ).getConfig(site_id, 'COPYRIGHT');
        if (!info)) {
            const info = [];
            info[ 'value' ] = [
                icp: '',
                gov_record: '',
                gov_url: '',
                market_supervision_url: '',
                logo: '',
                company_name: '',
                copyright_link: '',
                copyright_desc: ''
            ];
  }

  /**
   * getCopyright
   * 对应 PHP: CoreSysConfigService_core::getCopyright()
   * 逻辑类型: undefined - undefined
   */
  async getCopyright(site_id: any) {
    // 基于PHP真实逻辑: getCopyright
    // PHP原文: $info = ( new CoreConfigService() )->getConfig($site_id, 'COPYRIGHT');         if (empty($info)) {             $info = [];             $info[ 'value' ...
const info = ( this.coreConfigService ).getConfig(site_id, 'COPYRIGHT');
        if (!info)) {
            const info = [];
            info[ 'value' ] = [
                icp: '',
                gov_record: '',
                gov_url: '',
                market_supervision_url: '',
                logo: '',
                company_name: '',
                copyright_link: '',
                copyright_desc: ''
            ];
  }

  /**
   * getWapIndexList
   * 对应 PHP: CoreSysConfigService_core::getWapIndexList()
   * 逻辑类型: undefined - undefined
   */
  async getWapIndexList(data: any[]) {
    // 基于PHP真实逻辑: getWapIndexList
    // PHP原文: $result = array_filter(event("WapIndex", [ 'site_id' => $data[ 'site_id' ] ?? 0 ]));         if (empty($result)) return [];          $index_list = [];...
const result = array_filter(event("WapIndex", [ site_id: data[ 'site_id' ) || 0 ))];
        if (!result)) return [];

        const index_list = [];
        foreach (result as v) {
            const index_list = !index_list) ? v : any[]_merge(index_list, v);
  }

  /**
   * getMap
   * 对应 PHP: CoreSysConfigService_core::getMap()
   * 逻辑类型: undefined - undefined
   */
  async getMap(site_id: any) {
    // 基于PHP真实逻辑: getMap
    // PHP原文: $info = ( new CoreConfigService() )->getConfig($site_id, 'MAPKEY');         if (empty($info)) {             $info = [];             $info[ 'value' ] =...
const info = ( this.coreConfigService ).getConfig(site_id, 'MAPKEY');
        if (!info)) {
            const info = [];
            info[ 'value' ] = [
                is_open: 1, // 是否开启定位
                valid_time: 5 // 定位有效期/分钟，过期后将重新获取定位信息，0为不过期
            ];
  }
}
